#ifndef MKAHYPAR_COARSENER_BASE_H
#define MKAHYPAR_COARSENER_BASE_H

#include "mkahypar/utils/typedef.h"
#include "mkahypar/partition/context.h"
#include "mkahypar/partition/coarsening/coarsening_memento.h"
#include "mkahypar/partition/coarsening/hypergraph_pruner.h"

namespace mkahypar {

  class CoarsenerBase {
  public:
    CoarsenerBase(Hypergraph &hg,TargetGraph& topo) : _hg(hg),_topo(topo),
                                    _hypergraph_pruner(hg._initial_num_hypernodes) {

    }
    virtual ~CoarsenerBase() = default;
    CoarsenerBase(const CoarsenerBase&) = delete;
    CoarsenerBase& operator= (const CoarsenerBase&) = delete;
    CoarsenerBase(CoarsenerBase&&) = delete;
    CoarsenerBase& operator= (CoarsenerBase&&) = delete;

    //执行缩合
    void performContraction(const HypernodeID rep_node, const HypernodeID contracted_node) {
//      LOG<<"peform contract:"<<rep_node<<contracted_node;
      _history.emplace_back(_hg.contract(rep_node, contracted_node));
//      LOG<<"contract finish1!";

      removeSingleNodeHyperedges();
//      LOG<<"contract finish2!";

      removeParallelHyperedges();
//      LOG<<"contract finish3!";
    }

    void removeSingleNodeHyperedges() {
      _hypergraph_pruner.removeSingleNodeHyperedges(_hg, _history.back());
    }
    void removeParallelHyperedges() {
      _hypergraph_pruner.removeParallelHyperedges(_hg, _history.back());
    }
    void restoreParallelHyperedges() {
      _hypergraph_pruner.restoreParallelHyperedges(_hg, _history.back());
    }
    void restoreSingleNodeHyperedges() {
      _hypergraph_pruner.restoreSingleNodeHyperedges(_hg, _history.back());
    }

    HypergraphPruner _hypergraph_pruner;//负责删除单点边和平行边
    std::vector<CoarseningMemento> _history;//缩合历史
    Hypergraph &_hg;
    TargetGraph & _topo;
  };
}
#endif //MKAHYPAR_COARSENER_BASE_H
